package com.acme.entity;

import com.acme.entity.util.EntityBean;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author alejandro
 */
@Entity
@Table(name = "ZONARIESGO", catalog = "carreteras", schema = "dbo")
@NamedQueries({
    @NamedQuery(name = "ZonaRiesgo.findAll", query = "SELECT z FROM ZonaRiesgo z"),
    @NamedQuery(name = "ZonaRiesgo.findById", query = "SELECT z FROM ZonaRiesgo z WHERE z.id = :id"),
    @NamedQuery(name = "ZonaRiesgo.findByKilometro", query = "SELECT z FROM ZonaRiesgo z WHERE z.kilometro = :kilometro"),
    @NamedQuery(name = "ZonaRiesgo.findByDescripcion", query = "SELECT z FROM ZonaRiesgo z WHERE z.descripcion = :descripcion")})
public class ZonaRiesgo extends EntityBean<ZonaRiesgo> {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "id", nullable = false)
    private Integer id;
    @Column(name = "kilometro", length = 15)
    private String kilometro;
    @Column(name = "descripcion", length = 50)
    private String descripcion;
    @JoinColumn(name = "tramo", referencedColumnName = "id", nullable = false)
    @ManyToOne(optional = false)
    private Tramo tramo;

    public ZonaRiesgo() {
    }

    public ZonaRiesgo(Integer id) {
        this.id = id;
    }

    public ZonaRiesgo(Integer id, String kilometro, String descripcion, Tramo tramo) {
        this.id = id;
        this.kilometro = kilometro;
        this.descripcion = descripcion;
        this.tramo = tramo;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
        support.fireChange();
    }

    public String getKilometro() {
        return kilometro;
    }

    public void setKilometro(String kilometro) {
        this.kilometro = kilometro;
        support.fireChange();
    }

    public String getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(String descripcion) {
        this.descripcion = descripcion;
        support.fireChange();
    }

    public Tramo getTramo() {
        return tramo;
    }

    public void setTramo(Tramo tramo) {
        this.tramo = tramo;
        support.fireChange();
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof ZonaRiesgo)) {
            return false;
        }
        ZonaRiesgo other = (ZonaRiesgo) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return String.format("%s km%s (%s)",descripcion, kilometro, tramo);
    }

    @Override
    public ZonaRiesgo clone() {
        return new ZonaRiesgo(id, kilometro, descripcion, tramo);
    }

    @Override
    public void merge(ZonaRiesgo other) {
        this.id = other.id;
        this.kilometro = other.kilometro;
        this.descripcion = other.descripcion;
        this.tramo = other.tramo;
    }

}
